﻿using System;
using System.Linq;

namespace ECommerce.Controls
{
	public partial class MyCashTicket : BaseUserControl
	{
		private Service.ICashTicketService _CashTicketService;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BindMyCashTicket();
			}
		}

		private void BindMyCashTicket()
		{
			if (SiteContext.Current == null || SiteContext.Current.User == null)
			{
				Server.Transfer("~/Login.aspx");
			}

			var userID = SiteContext.Current.User.ProviderUserKey as Guid?;

			if (userID.HasValue)
			{
				if(_CashTicketService == null)
				{
					_CashTicketService = new Service.CashTicketService();
				}
				var cashTickets = _CashTicketService.GetMyCashTicket(userID.Value);
				if (cashTickets != null)
				{
					RepeaterCashTickets.DataSource = cashTickets.Where(exp => exp.IsUsed == 0);
					RepeaterCashTickets.DataBind();
				}
			}
		}
	}
}